import 'package:just_audio/just_audio.dart';
import 'package:logger/logger.dart';


class SoundService {

  final _logger = Logger();

  final AudioPlayer _player = AudioPlayer();

  SoundService();

  Future<void> playSource(String path) async {
    _logger.i('[audio play start]', time: DateTime.now());
    try {
      _player.setLoopMode(LoopMode.all);
      await _player.setAsset(path);
      await _player.play();
    } catch(error, stacktrace) {
      _logger.e("[audio play error]", error: error, stackTrace: stacktrace, time: DateTime.now());
    }
  }

  Future<void> stop() async {
    await _player.stop();
  }
}